import { request } from 'umi';

/**
* get one record by id
*/
export async function getTakeAwayShopById(id: number, params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayShopType.TakeAwayShopResponse>>(`/api/takeAwayShop/getById/${id}`, {
        method: 'GET',
        params: params
    });
}

/**
* get all records
*/
export async function getTakeAwayShopAll(params: object = {}) {
    return request<ApiResponse.ResultModel<TakeAwayShopType.TakeAwayShopResponse>>(`/api/takeAwayShop/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* get records by page
*/
export async function getTakeAwayShopPageList(params: object = {}) {
    return request<PageInfo.PageResponse<TakeAwayShopType.TakeAwayShopResponse>>(`/api/takeAwayShop/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* update partial field of record
*/
export async function commonUpdate(id: number, fieldName: string, value: string) {
    return request<ApiResponse.ResultModel<TakeAwayShopType.TakeAwayShop>>(`/api/takeAwayShop/PatchById?id=${id}`, {
        method: 'PATCH',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [{
            "id": id,
            "op": "replace",
            "path": `/${fieldName}`,
            "value": value

        }]
    });
}

/*
* update record
*/
export async function updateTakeAwayShop(data: TakeAwayShopType.TakeAwayShopRequest, params: object) {
  debugger
  return request<ApiResponse.ResultModel<TakeAwayShopType.TakeAwayShopResponse>>(`/api/takeAwayShop/put`, {
    method: 'put',
    headers: {
      'Content-Type': 'application/json',
    },
    data: [data],
    params: params
  });
}

/*
* add one record
*/
export async function addTakeAwayShop(data: TakeAwayShopType.TakeAwayShopRequest, params: object) {
  debugger
  return request<ApiResponse.ResultModel<TakeAwayShopType.TakeAwayShopResponse>>('/api/takeAwayShop/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: [data],
    params: params
  });
}

export async function deleteTakeAwayShop(params: DeleteRequest) {
    return request<ApiResponse.ResultModel<boolean>>(`/api/takeAwayShop/delete`, {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params.id],
    });
}
